package de.ifi.lmu.snitzelhunt.participants;

import de.ifi.lmu.snitzelhunt.R;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;

/**
 * 
 * @author Sebastian Siepe
 * 
 */
public class PopupActionTask extends DialogFragment {
	private String message = "";
	private Long penaltyTime = 5L;
	private Long noPenaltyTime = 0L;
	private Intent nextTask = new Intent("NEXT_TASK");

	// set String
	public void setMessage(String message) {
		this.message = message;
	}

	@Override
	public void show(FragmentManager manager, String tag) {
		// TODO Auto-generated method stub
		try {
			super.show(manager, tag);
		} catch (IllegalStateException ex) {
		}
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {

		// 1. Instantiate an AlertDialog.Builder with its constructor
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

		// 2. Chain together various setter methods to set the dialog
		// characteristics
		builder.setTitle(R.string.popup_actiontask_title);
		builder.setIcon(getResources().getDrawable(R.drawable.actionicon));
		builder.setMessage(message);

		// 3. Get the AlertDialog from create()
		// AlertDialog dialog = builder.create();

		builder.setNegativeButton(R.string.popup_actiontask_button,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						nextTask.putExtra("PENALTY_TIME", noPenaltyTime);
						getActivity().sendBroadcast(nextTask);
						dismiss();
					}
				}).setPositiveButton(R.string.popup_actiontask_negative_button,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						nextTask.putExtra("PENALTY_TIME", penaltyTime);
						getActivity().sendBroadcast(nextTask);
						dismiss();
					}
				});

		// Create the AlertDialog object and return it
		return builder.create();
	}
}